﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static WinFormsApp1.TongShiWei.COA.LivestockData;

namespace WinFormsApp1.TongShiWei.COA
{
    public partial class LivestockData : UIForm
    {
        public LivestockData()
        {
            InitializeComponent();
            ShowLivestockData();
        }
        public delegate void GetGoodsId(int GoodsId,string GoodsName);
        public event GetGoodsId OnGetGoodsId;
        #region 活畜到厂列表
        public void ShowLivestockData()
        {
            List<Livestock> livestocks = new List<Livestock>()
            {
                new Livestock{LivestockId=1,LivestockTime=DateTime.Parse("2023-10-30"),GoCourseDataNum="2001-0202",GoCourseDataLot="109",SupplierName="牧原股份",UPCName="二元猪",PlanButcher="一圈,二圈,三圈",StorageNum=100,CreateAddr="辽宁" },
                new Livestock{LivestockId=2,LivestockTime=DateTime.Parse("2023-11-10"),GoCourseDataNum="2001-0203",GoCourseDataLot="109",SupplierName="乡村黑猪股份",UPCName="三元猪",PlanButcher="一圈,二圈,三圈",StorageNum=100,CreateAddr="辽宁" },
                new Livestock{LivestockId=3,LivestockTime=DateTime.Parse("2023-11-15"),GoCourseDataNum="2001-0204",GoCourseDataLot="109",SupplierName="旺猪股份",UPCName="一元猪",PlanButcher="一圈,二圈,三圈",StorageNum=100,CreateAddr="辽宁" },
            };
            foreach (Livestock item in livestocks)
            {
                this.dataGridView1.Rows.Add(false, item.LivestockId, item.LivestockTime.ToString(), item.GoCourseDataNum, item.GoCourseDataLot, item.SupplierName, item.UPCName, item.PlanButcher, item.StorageNum, item.CreateAddr);
            }
        }
        public class Livestock
        {
            //活畜到厂ID
            public int LivestockId { get; set; }
            //到场时间
            public DateTime LivestockTime { get; set; }
            //进场编号
            public string GoCourseDataNum { get; set; }
            //进场批次
            public string GoCourseDataLot { get; set; }
            //供应商
            public string SupplierName { get; set; }
            //商品代号
            public string UPCName { get; set; }
            //待宰圈
            public string PlanButcher { get; set; }
            //圈存头数
            public int StorageNum { get; set; }
            //产地
            public string CreateAddr { get; set; }
            public int pid { get; set; }
        }
        #endregion

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex > 0)
            {
                return;
            }
            else
            {
                this.dataGridView1.Rows[e.RowIndex].Cells[0].Value = this.dataGridView1.Rows[e.RowIndex].Cells[0].Value = true ? false : true;
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (row.Index != e.RowIndex)
                    {
                        this.dataGridView1.Rows[row.Index].Cells[0].Value = false;
                    }
                }
            }
        }
        //选择
        private void uiButton1_Click(object sender, EventArgs e)
        {
            int GetNum = 0;
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if ((bool)this.dataGridView1.Rows[row.Index].Cells[0].Value==true)
                {
                    GetNum++;
                    int LivestockId=Convert.ToInt32(this.dataGridView1.Rows[row.Index].Cells[1].Value);
                    string LivestockName = this.dataGridView1.Rows[row.Index].Cells[6].Value.ToString();
                    OnGetGoodsId?.Invoke(LivestockId, LivestockName);
                    this.Close();
                }
            }
            if(GetNum==0)
            {
                MessageBox.Show("还没有选择商品");
            }
        }
    }
}
